<template>
  <div class="fllow-user">
    <!-- <div class="follow-infos"> -->
      <scroller :on-refresh="refresh" :on-infinite="infinite">
        <div class="mine">
          <img class="left-action" @click="$router.go(-1)" src="../../../assets/imgs/icon-back@2x.png" alt="">
          <div class="right-action" @click="handleAttention">{{this.isAtten?'已关注':'关注'}}</div>
          <!-- <img @click="showSelectModal=true" class="right-action" slot="right" src="../../../assets/imgs/live/schedule@2x.png" alt=""> -->
          <div class="banner">
            <div class="user-info">
              <div class="avator">
                <img src="../../../assets/imgs/home/home_menu2@2x.png" alt="">
              </div>
              <div class="name">
                {{memberData.nickname}}
              </div>
              <div class="watch">
                关注  {{memberData.follow_num}}   |  粉丝  {{memberData.fans_num}}
              </div>
            </div>
          </div>
          <div class="money">
            <div class="money-item">
              <div class="label">近7天命中</div>
              <div class="num">{{memberData.hit_rate || 0}}</div>
            </div>
            <div class="money-item">
              <div class="label">7天奖金</div>
              <div class="num">{{memberData.bonus_price}}</div>
            </div>
            <div class="money-item">
              <div class="label">7天胜率</div>
              <div class="num">{{memberData.bonus_odds}}</div>
            </div>
          </div>
        </div>
        <!-- <fllow-item :isDetail="true" :showWin="true"></fllow-item>
        <fllow-item ></fllow-item> -->
        <div class="fllow-list vtop" v-if="followBillList.length"
        :class="{'loaded-data': followBillList.length < 3, 'loadmore-data': followBillList.length < 5}" >
          <div class="fllow-item" v-for="(item, index) in followBillList" :key="index" @click="$router.push({ path: `/follow/detail/${item.bill_id}` })">
            <div class="cate-cell bd1px">
              <img  v-if="item.lottery_type==2" src="../../../assets/imgs/home/icon-hot2@2x.png" alt>
              <img v-else src="../../../assets/imgs/home/icon-hot1@2x.png" alt>
              <span class="title">{{`${item.desc || '百中百发，快来和我一起赚钱吧！'}`}}</span>
            </div>
            <ul class="fllow-detail">
              <li>自购
                <span>¥ {{item.total_price}}</span>
              </li>
              <li>起跟
                <span>¥ {{item.min_price}}</span>
              </li>
              <li>人数
                <span>{{item.person_num}}</span>
              </li>
              <li v-if="!item.is_bet && item.state == 2">奖金
                <span>¥ {{item.total_bonus_price}}</span>
              </li>
              <!-- <li v-if="item.is_bet==1">
                <span class="fllow-btn" @click="$router.push({ path: `/follow/detail/${item.bill_id}` })">跟单</span>
              </li> -->
              <li v-if="item.state != 2">
                <span class="fllow-btn" @click="$router.push({ path: `/follow/detail/${item.bill_id}` })">跟单</span>
              </li>
            </ul>
            <div class="times">
              <span class="time">截止: {{item.end_time}}</span>
              <span class="time" v-show="item.state>=2">开奖: {{item.bonus_time}}</span>
            </div>
            <div class="follow-type" v-if="!item.is_bet"> <!-- state 订单状态  1待开奖 2已中奖 3未中奖 -->
              <img v-if="item.state==2" src="../../../assets/imgs/home/icon-winning@2x.png" alt="">
              <img v-if="item.state==3" src="../../../assets/imgs/home/icon-notwinning@2x.png" alt="">
            </div>
          </div>
        </div>
      </scroller>
    <!-- </div> -->
    <div class="no-data" v-if="!loading && !followBillList.length">
      <img src="../../../assets/imgs/icon-noattention@2x.png" alt="">
      <div class="desc">暂无数据</div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
import FllowItem from '@/components/FllowUserItem';
import CateCell from '@/components/CateCell';

export default {
  components: {
    FllowItem,
    CateCell
  },
  data () {
    return {
      pageNum: 1,
      isPull: false, // 下拉
      loading: true,
      isDetail: false,
      showWin: true,
      isAtten: false, // 是否关注
      memberData: {
        // avatar: 'https://www.try255.com/statics/avatar/1_160.png',
        // bonus_odds: '0%',
        // bonus_price: '0',
        // fans_num: '0',
        // follow_num: '0',
        // hit_rate: '',
        // is_follow: 0,
        // member_id: 1,
        // nickname: '嘻嘻啊1'
      },
      followBillList: []
    }
  },
  mounted () {
    const query = this.$route.params;
    if (query.id) {
      this.memberId = query.id;
      this.getMemberInfo();
      // this.getDatas(); // 跟单列表
    }
  },
  methods: {
    ...mapActions({
      getOtherMemberInfo: 'home/getOtherMemberInfo',
      getFollowBillList: 'follow/getFollowBillList',
      getFollow: 'attention/getFollow',
      getUnFollow: 'attention/getUnFollow'
    }),
    refresh (done) { // 下拉
      this.isPull = true;
      this.pageNum = 1;
      this.loading = true;
      this.getDatas(done);
      this.getMemberInfo();
    },
    infinite (done) { // 上滑
      if (!this.isPull) {
        this.loading = true;
        this.getDatas(done);
      }
    },
    getDatas (done) {
      if (this.loading) {
        const params = {
          member_id: this.memberId,
          page: this.pageNum,
          size: 10
        }
        this.getFollowBillList(params).then(res => {
          this.loading = false;
          let listData = res.list || [];
          if (listData.length) {
            if (this.isPull) {
              this.isPull = false;
              this.followBillList = [];
            }
            this.pageNum += 1;
            const listDatas = this.followBillList;
            this.followBillList = listDatas.concat(listData);
            if (this.pageNum < res.page.total) {
              done(true);
            } else {
              done(2); ;
            }
          } else {
            done(2);
          }
        });
      }
    },
    getDatas1111 (page) {
      this.getFollowBillList({ page, member_id: this.memberId }).then(res => {
        if (res) {
          const followLists = this.followBillList;
          const followData = res.list || [];
          this.followBillList = followLists.concat(followData);
        }
      });
    },
    getMemberInfo () {
      this.getOtherMemberInfo({ member_id: this.memberId }).then(res => {
        if (res) {
          this.isAtten = res.is_follow || false;
          this.memberData = res || {};
        }
      });
    },
    handleAttention () {
      if (this.isAtten) {
        this.getUnFollow({follower_id: this.memberData.member_id}).then(res => {
          this.isAtten = false;
        })
      } else {
        this.getFollow({follower_id: this.memberData.member_id}).then(res => {
          this.isAtten = true;
        })
      }
    }

  }
}
</script>
<style lang="less" scoped>
  .fllow-user {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    overflow-y: auto;
    // padding-bottom: 0.2rem;
    // box-sizing: border-box;
      .left-action {
        position: absolute;
        top: 0;
        left: 0;
        display: inline-block;
        width: 0.23rem;
        height: 0.4rem;
        padding: 15px 0.3rem 0;
        line-height: 21px;
        z-index: 1;
      }
      .right-action {
        position: absolute;
        top: 0.25rem;
        right: 0.2rem;
        width: 1.13rem;
        height: 0.5rem;
        line-height: 0.5rem;
        font-size: 0.24rem;
        color: #ffffff;
        text-align: center;
        background-color: #d44743;
        border: 0.02rem solid #fff;
        border-radius: 0.06rem;
        box-sizing: border-box;
        z-index: 1;
        &.on {
          color: #d44743;
          background-color: #fff;
        }
      }
    .mine{
      position: relative;
      .banner {
        height: 2.72rem;
        .user-info {
          position: absolute;
          background: #D44743;
          width: 100%;
          height: 2.32rem;
          text-align: center;
          // margin-left: -3.75rem;
          // left: 50%;
          padding-top: 0.4rem;
          .avator {
            img {
              width: 1.2rem;
              height: 1.2rem;
              border-radius: 50%;
            }
          }
          .name {
            margin-top: 0.2rem;
            color: #FFFFFF;
            font-size: 0.3rem;
            // height: 0.4rem;
          }
          .watch {
            margin-top: 0.13rem;
            color: #FFFFFF;
            font-size: 0.24rem;
            // height: 0.32rem;
          }
        }
      }
      .money {
        display: flex;
        height: 1rem;
        background: #FFFFFF;
        .money-item {
          flex: 1;
          position: relative;
          margin-top: 0.14rem;
          text-align: center;
          &::before {
            content: '';
            display: block;
            width: 0.01rem;
            height: 0.4rem;
            background:  #D2D2D2;
            position: absolute;
            left: 0;
            top: 20%;
            z-index: 1;
          }
          &:first-child::before {
            display: none;
          }
          .num{
            color: #D44743;
            font-size: 0.32rem;
            line-height: 0.46rem;
          }
          .label{
            color: #999999;
            font-size: 0.24rem;
            line-height: 0.32rem;
          }
        }
      }
    }
    .fllow-item {
      position: relative;
      margin-top: 0.2rem;
      background: #ffffff;
      .cate-cell {
        position: relative;
        width: 100%;
        height: 0.76rem;
        line-height: 0.8rem;
        background: #ffffff;
        &.bd1px:after {
          content: " ";
          display: block;
          position: absolute;
          width: 100%;
          bottom: 0;
          height: 1px;
          border-bottom: 1px solid #d2d2d2;
          color: #d2d2d2;
          transform-origin: 0 100%;
          transform: scaleY(0.5);
        }
        img {
          display: inline-block;
          width: 0.4rem;
          margin-left: 0.2rem;
          margin-right: 0.1rem;
        }
        .title {
          font-size: 0.26rem;
          color: #333333;
        }
      }
      .fllow-detail {
        position: relative;
        display: flex;
        // &::before {
        //   content: '';
        //   display: block;
        //   position: absolute;
        //   width: 100%;
        //   top: -1px;
        //   height: 1px;
        //   border-top: 1px solid #d2d2d2;
        //   color: #d2d2d2;
        //   transform-origin: 0 100%;
        //   transform: scaleY(0.5);
        // }
        &::after {
          content: "";
          display: block;
          position: absolute;
          width: 100%;
          bottom: 0;
          height: 1px;
          border-bottom: 1px solid #d2d2d2;
          color: #d2d2d2;
          transform-origin: 0 100%;
          transform: scaleY(0.5);
        }
        li {
          position: relative;
          flex: 1;
          height: 0.8rem;
          line-height: 0.8rem;
          font-size: 0.28rem;
          color: #666666;
          text-align: center;
          &::after {
            content: "";
            display: block;
            position: absolute;
            top: 0;
            right: 0;
            width: 1px;
            height: 0.8rem;
            background: #d2d2d2;
            transform: scaleX(0.5);
          }
          &:last-child::after {
            display: none;
          }
          span {
            color: #d44743;
          }
          .fllow-btn {
            display: inline-block;
            padding: 0 0.4rem;
            height: 0.6rem;
            line-height: 0.6rem;
            font-size: 0.3rem;
            color: #ffffff;
            background: #d44743;
            border-radius: 0.06rem;
          }
        }
      }
      .times {
        height: 0.6rem;
        line-height: 0.6rem;
        padding: 0 0.2rem;
        font-size: 0.22rem;
        color: #999999;
        overflow: hidden;
        span:last-child {
          float: right;
          min-width: 1.8rem;
        }
      }
      .follow-type {
        position: absolute;
        top: 0.2rem;
        right: 0.2rem;
        width: 0.8rem;
        height: 0.8rem;
        img {
          display: block;
          width: 100%;
        }
      }
    }
    .no-data {
      position: fixed;
      width: 100%;
      top: 3.82rem;
      bottom: 0;
      height: 100%;
      text-align: center;
      background: #ffffff;
      img {
        display: block;
        width: 4.15rem;
        height: 3.22rem;
        margin: 0 auto;
        padding-top: 0.8rem;
      }
      .desc {
        margin-top: 0.3rem;
        font-size: 0.22rem;
        color: #919191;
      }
    }
  }
</style>
